package com.tavenli.services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tavenli.entity.DeviceCmdEntity;
import com.tavenli.entity.F18Device;
import com.tavenli.model.PageData;
import com.tavenli.repository.DeviceCmdDao;

@Service
public class DeviceCmdService {
	private static Logger logger = LoggerFactory
			.getLogger(UCenterService.class);
	
	@Autowired
	private DeviceCmdDao deviceCmdDao;
	
	/**
	 * 生成检查数据更新的命令
	 * @return
	 */
	public String getCheckCmd() {
		return "CHECK\r\n";
	}
	/**
	 * 生成清理考勤记录的命令
	 * @return
	 */
	public String getClearLogCmd() {
		return "CLEAR LOG\r\n";
	}
	/**
	 * 生成所有数据的命令
	 * @return
	 */
	public String getClearAllDataCmd() {
		return "CLEAR LOG\r\n";
	}
	/**
	 * 生成获取设备配置信息的命令
	 * @return
	 */
	public String getDeviceInfoCmd() {
		return "INFO\r\n";
	}
	/**
	 * 更新设备对应的设置
	 * @param args
	 * @param val
	 * @return
	 */
	public String getSetDeviceOptionsCmd(String args,String val) {
		return String.format("SET OPTION %s=%s\r\n", args,val);
	}
	/**
	 * 生成重启设备命令
	 * @return
	 */
	public String getRebootCmd() {
		return "REBOOT\r\n";
	}
	/**
	 * 获取重新加载参数的cmd命令，执行完getSetDeviceOptionsCmd方法后执行此方法
	 * @return
	 */
	public String getReLoadOptionsCmd() {
		return "RELOAD OPTIONS\r\n";
	}
	
	
	
	public PageData<DeviceCmdEntity> getDeviceCmdList(Integer pageIndex,
			int pageSize, String sn) {
		PageData<DeviceCmdEntity> pageData = new PageData<DeviceCmdEntity>(pageIndex, pageSize);
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("sn", sn);
		int totalCount = deviceCmdDao.queryDataCount(paramMap);
		List<DeviceCmdEntity> list = deviceCmdDao.queryPageData(pageData.getStartRow(), pageSize,paramMap);
		pageData.setTotalCount(totalCount);
		pageData.setPageData(list);
		return pageData;
	}
	
	
	
	
}
